using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using Sedna.Core.Common;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;
using Sedna.Core.Common.Objects.Navigation;

namespace Sedna.Core.Controls.Actions.Support
{

	public class BaseFilterAction : AbstractAction
	{

        private string filterStateBindPath = null;
        private string filterStateUnbindPath = null;
	    
	    public string FilterStateBindPath
	    {
	        get
	        {
                return this.filterStateBindPath;
	        }
	        set
	        {
                this.filterStateBindPath = value;
	        }
	    }

        public string FilterStateUnbindPath
        {
            get
            {
                return this.filterStateUnbindPath;
            }
            set
            {
                this.filterStateUnbindPath = value;
            }
        }

	    protected object GetFilter()
	    {
            return scopePathParser.Parse(this.FilterStateBindPath).Value;
	    }
	    protected void SetFilter(object filter)
        {
            scopePathParser.Parse(this.FilterStateUnbindPath).Value = filter;           
        }
	    protected void ResetFilter(object filter)
	    {           
            scopePathParser.Parse(this.FilterStateBindPath).Value = filter;
            SetFilter(filter);
	    }
	    protected void ResetFilter(bool CreateEmptyFilter)
	    {
            ResetFilter((CreateEmptyFilter) ? Activator.CreateInstance(GetFilter().GetType()) : null);
	    }
        protected void ResetFilter()
        {
            ResetFilter(false);
        }
	    
		public override IActionResult Execute(IExecutionContext executionContext)
		{
//			IDataAccessFilter filter = GetFilter(httpContext, executionContext);
//			SetupSorting(filter, executionContext);
//			SetupPaging(filter, executionContext);
			ICollection resultSet = GetResultSet(null, executionContext);
			executionContext.SetToCurrentScope("data", resultSet); 
			return CreateResult(successStatus);
		}

		protected virtual ICollection GetResultSet(object filter, IExecutionContext executionContext)
		{
			return GetResultSet(filter);
		}

		protected virtual ICollection GetResultSet(object filter)
		{
			DataTable table = new DataTable();
			ICollection resultSet = table.DefaultView;
			return resultSet;
		}

//		protected virtual IDataAccessFilter GetFilter(HttpContext httpContext, IExecutionContext executionContext)
//		{
//			IDataAccessFilter filter = null;
//			return filter;
//		}
//
//		protected virtual void SetupSorting(IDataAccessFilter filter, IExecutionContext executionContext)
//		{
//			FilterSetupUtil.SetupSorting(filter, executionContext);
//		}
//
//
//		protected virtual void SetupPaging(IDataAccessFilter filter, IExecutionContext executionContext)
//		{
//			FilterSetupUtil.SetupPaging(filter, executionContext);
//		}

	}
}
